package com.youlu.campus.admin.utils.excel;

import com.alibaba.excel.event.AnalysisEventListener;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

public abstract class ExcelListener<T> extends AnalysisEventListener<T> {

    protected List<T> dataList = new ArrayList<>();

    protected List<String> errorMessages = new ArrayList<>();

    protected List<Integer> errorRows = new ArrayList<>();

    protected boolean success = true;

    public List<T> getDataList() {
        return dataList;
    }

    public List<String> getErrorInfo() {
        return errorMessages;
    }

    public boolean isSuccess() {
        return success;
    }

    public boolean isEmpty() {
        return dataList.isEmpty();
    }

    public List<Integer> getErrorRows() {
        return errorRows;
    }

    public String getErrorMessage() {
        if (CollectionUtils.isEmpty(errorMessages)) {
            return "解析成功";
        }
        return "第" + StringUtils.join(errorRows, ",") + "行数据错误";
    }
}
